using System;
using System.Security.Permissions;
using Microsoft.Win32.SafeHandles;

namespace WindowsAPI
{
    [SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)]
    public sealed class SafeObjectHandle : SafeHandleZeroOrMinusOneIsInvalid
    {
        private SafeObjectHandle() : base(true) { }

        internal SafeObjectHandle(IntPtr preexistingHandle, bool ownsHandle) : base(ownsHandle) { SetHandle(preexistingHandle); }

        protected override bool ReleaseHandle() { return Kernel32.CloseHandle(handle); }
    }
}